import subprocess

def run_sqoop_import(hive_table, mysql_table):
    sqoop_command = (
        f"sqoop import "
        f"--connect jdbc:mysql://your_mysql_host:3306/your_database "
        f"--username your_username "
        f"--password your_password "
        f"--table {mysql_table} "
        f"--hive-table {hive_table} "
        f"--num-mappers 1"
    )
    print(f"Executing: {sqoop_command}")
    try:
        result = subprocess.run(sqoop_command, shell=True, check=True)
        print(f"Command executed with return code: {result.returncode}")
    except subprocess.CalledProcessError as e:
        print(f"Error executing command: {e}")

if __name__ == "__main__":
    # MySQL和Hive表名一一对应
    tables = {
        "ads_age": "ads_age",
        "ads_market": "ads_market",
        "ads_sex": "ads_sex",
        "ads_times": "ads_times",
        "ads_province": "ads_province",
        "ads_opu": "ads_opu",
    }

    # 遍历字典并执行导入
    for hive_table, mysql_table in tables.items():
        run_sqoop_import(hive_table, mysql_table)